package com.gs.wzmanager.service.impl;

import com.gs.wzmanager.dao.ChannelDao;
import com.gs.wzmanager.entity.Channel;
import com.gs.wzmanager.service.ChannelService;
import com.gs.wzmanager.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    ChannelDao channelDao;

    @Override
    public List<Channel> queryAllChannel() {
        return channelDao.queryAllChannel();
    }

    @Override
    public ResponseEntity update(Channel channel) {
        if (channelDao.updateChannel(channel)) {
            return HttpUtils.buildStringResponse("Ok", HttpStatus.OK);
        } else {
            return HttpUtils.buildStringResponse("ERR", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

    @Override
    public ResponseEntity addChannel(Channel channel) {
        if (channelDao.addChannel(channel)) {
            return HttpUtils.buildStringResponse("Ok", HttpStatus.OK);
        } else {
            return HttpUtils.buildStringResponse("ERR", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}
